<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2014.07.28.
   家居统计控制器($$)*/

!defined('Q_PATH') && exit;

class JiajucountController extends AController{

	public function index($sModel=null,$bDisplay=true){
		$this->display(Admin_Extend::template('jiaju','jiajucount/index'));
	}

	public function updatecount(){
		set_time_limit(0);

		$sMessage='';
		$nNum=intval(Q::G('num','G'));
		$nPage=intval(Q::G('p','G'));
		$nDonum=intval(Q::G('donum','G'));

		if($nNum<10){
			$nNum=10;
		}elseif($nNum>5000){
			$nNum=5000;
		}
		if($nPage<1){
			$nPage=1;
		}

		$nTotalNum=Model::F_('jiajucompany','jiajucompany_status=1')
			->getCounts();
		
		$oCompany=Q::instance('JiajucompanyModel');
		$arrCompanys=Model::F_('jiajucompany','jiajucompany_status=1')
			->setColumns('jiajucompany_id,jiajucompany_fullname')
			->limit($nDonum,$nNum)
			->order('jiajucompany_id DESC')
			->getAll();
		foreach($arrCompanys as $arrCompany){
			$oCompany->updateCount($arrCompany['jiajucompany_id']);
			$sMessage.='<span style="line-height:25px;height:25px;margin-right:55px;">'.$arrCompany['jiajucompany_fullname'].' ('.$arrCompany['jiajucompany_id'].')</span>';
		}
		$nDonum+=count($arrCompanys);

		if($nDonum>=$nTotalNum){
			$this->assign('__JumpUrl__',Admin_Extend::base(array('controller'=>'jiajucount')));
			$this->S('数据统计更新完毕');
		}

		$sPercentBar=round($nDonum/$nTotalNum,2)*100;
		$sUrl=Admin_Extend::base(array('controller'=>'jiajucount','action'=>'updatecount','num'=>$nNum,'p'=>$nPage+1,'donum'=>$nDonum));
		
		$this->assign('sPercentBar',$sPercentBar);
		$this->assign('sUrl',$sUrl);
		$this->assign('sMessage',$sMessage);

		$this->display(Admin_Extend::template('jiaju','jiajucount/updatecount'));
	}

}
